function courseStatistics() {
    var _this = this;
    var page;
    _this.index = -1;
    var items;
    _this.init = function (page_person) {
        page = page_person;
        _this.initTable();
        _this.initEvent();
    };
    _this.initEvent = function () {

        var userIdAll = [];
        var object = {};
        /**
         * 全选事件
         */
        $("#checkAll").click(function () {
                if (this.checked) {
                    $("#course_table :checkbox:not(:disabled)").prop("checked", true);

                    $("#course_table :checkbox:not(:disabled)").each(function () {
                        if (!object[$(this).val()]) {
                            object[$(this).val()] = 1;
                            userIdAll.push($(this).val());
                        }
                    });
                } else {
                    $("#course_table :checkbox:not(:disabled)").prop("checked", false);
                    if (userIdAll.length > 0) {
                        for (var a = 0; a < userIdAll.length; a++) {
                            $("#course_table :checkbox:not(:disabled)").each(function () {
                                if ($(this).val() === userIdAll[a]) {
                                    delete object[$(this).val()];
                                    userIdAll.splice(a, 1);
                                }
                            })
                        }
                    }
                }
                // console.log(userIdAll);
            }
        );

        /**
         * 单选事件
         */
        $("#course_table").on("click", "input[type=checkbox]", function () {
            if ($(this).is(":checked")) {
                if (!object[$(this).val()]) {
                    object[$(this).val()] = 1;
                    userIdAll.push($(this).val());
                }
            } else {
                if (userIdAll.length > 0) {
                    for (var a = 0; a < userIdAll.length; a++) {
                        if ($(this).val() === userIdAll[a]) {
                            delete object[$(this).val()];
                            userIdAll.splice(a, 1);
                        }
                    }
                }
            }
            // console.log(userIdAll);
        });
        /**
         *
         * 清空所有的选择
         */
        /*$("#clearSelAll").on("click", function () {
         object={};
         userIdAll = [];
         });*/


        /*导出*/
        $("#btn_ex").click(function () {
            // 导出模板名称
            /*var ids = '';
             $(":checkbox[name='ckbox']:checked").each(function () {
             ids += $(this).val() + ',';
             });*/
            var text = $("#course_table tr:eq(0)").text();
            if (!text) {
                layer.msg("暂无数据，不能导出");
                return;
            }
            _this.index = layer.alert('是否确定导出', {
                btn: ['确定', '取消'],
                btn1: function () {
                    var fileName = "课程统计 " + new Date().getTime() + ".xlsx";
                    var courseName = $("#courseName").val();
                    var year = $("#year").val();
                    var sortBy = $("#sortBy").val();
                    var descAsc = $("#descAsc").val();
                    window.location.href = appPath + '/admin/course/statistics/excel_export?fileName=' + fileName + '&courseName=' + courseName + '&year=' + year + '&sortBy='+ sortBy + '&descAsc=' + descAsc;
                    layer.close(courseStatistics.index);
                }
            })


        });
    }
    _this.initTable = function () {
        var list_url = appPath + "/admin/course/statistics/list";
        page.init("course_form", list_url, "course_table", "course_page", 1, 10);
        page.goPage(1);
        page.list = function (dataList) {
            $("#checkAll").attr("checked", false);
            var len = dataList.length;
            items = dataList;
            var inner = "", item;
            // 组装数据
            for (var i = 0; i < len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td>' + item.varCode + '</td>';
                inner += '<td>' + item.varName + '</td>';
                inner += '<td>' + item.chrSource + '</td>';
                inner += '<td>' + item.personCount + '</td>';
                inner += '<td>' + item.useNum + '</td>';
                inner += '<td>' + item.useNumRate.toFixed(2) + '</td>';
                inner += '</tr>';
            }
            return inner;
        }


        _this.info = function (varId) {
            window.open(appPath + "/admin/trainRole/trainRoleInfo?varId=" + varId, "_blank");
            // window.location.href = appPath + "/admin/trainRole/trainRoleInfo?varId=" + varId;
        }

        _this.search = function () {
            _this.initTable();
        };
        _this.searchAll = function () {
            $("#courseName").val("");
            $("#year").val("");
            _this.initTable();
        };
        _this.ajax = function (url, param, type) {
            var result;
            $.ajax({
                url: url,
                async: false,
                type: 'post',
                data: param,
                success: function (data) {
                    result = data;

                }
            });
            return result;
        };

        // 项目自定义排序
        _this.sort_off = function (value, obj) {
            $("#sortBy").val(value);
            var order = obj.className
            if (order == 'sort asc') {
                $("#descAsc").val('desc')
            } else {
                $("#descAsc").val('asc')
            }
            // 刷新列表
            _this.initTable();
        }

    }

}

var courseStatistics = new courseStatistics();